/**
 * Copyright (C), 2015-2019, XXX有限公司
 * FileName: AjaxAuthenticationEntryPoint
 * Author:   kadibeieun
 * Date:     2019/8/8 11:02
 * Description: 用户未登录时返回给前端的数据
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.mengde.security;

import com.alibaba.fastjson.JSON;
import com.mengde.common.ResultEnum;
import com.mengde.common.vo.ResultVO;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 〈一句话功能简述〉<br> 
 * 〈用户未登录时返回给前端的数据〉
 *
 * @author kadibeieun
 * @create 2019/8/8
 * @since 1.0.0
 */
@Component
public class AjaxAuthenticationEntryPoint implements AuthenticationEntryPoint {

    @Override
    public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
        httpServletResponse.getWriter().write(JSON.toJSONString(ResultVO.result(ResultEnum.USER_NEED_AUTHORITIES,false)));

    }
}